package com.neusoft.elmboot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import com.neusoft.elmboot.po.CreditConfig;
import com.neusoft.elmboot.po.CreditTransaction;

@Mapper
public interface CreditTransactionMapper {

	@Insert("insert into credittransaction (userId,channalId,eventId,credit,createTime,expiredTime) "
			+ "values (#{userId},#{channalId},#{eventId},#{credit},#{createTime},#{expiredTime})")
	@Options(useGeneratedKeys = true, keyProperty = "Id")
	public int saveCreditTransaction(CreditTransaction creditTransaction);
	
	//查询未过期的所有积分数据
	@Select("select * from credittransaction where userId=#{userId} and "
			+ "((STR_TO_DATE(expiredTime, '%Y-%m-%d %H:%i:%s') > NOW()) or credit < 0 )")
	public List<CreditTransaction> listCreditTransactionByUserId(String userId);
	
	//查询已使用的积分数据
	@Select("select * from credittransaction where userId=#{userId} and credit < 0")
	public List<CreditTransaction> listUsedCreditTransactionByUserId(String userId);
	
	//读取配置
	@Select("select * from creditconfig where creditConfigId=#{creditConfigId}")
	public CreditConfig getCreditConfig(Integer configId);
}
